home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / Clean 1.2.4 / StdEnv / StdTuple.icl < prev   
Encoding:
Modula Implementation  |  1996-12-23  |  1.8 KB  |  67 lines  |  [TEXT/3PRM]

  1. implementation module StdTuple
  2.  
  3. // ****************************************************************************************
  4. //    Concurrent Clean Standard Library Module Version 1.1
  5. //    Copyright 1995 University of Nijmegen
  6. // ****************************************************************************************
  7.  
  8. // Standard Functions on Tuples:
  9.  
  10. import StdClass, StdBool
  11.  
  12. instance ==    (a,b) |    Eq a & Eq b
  13.     where
  14.     (==) ::!(a,b) !(a,b) -> Bool    |    Eq a & Eq b
  15.     (==) (x1,y1) (x2,y2) = x1==x2 && y1==y2
  16.     
  17. instance == (a,b,c)    | Eq a & Eq b & Eq c
  18.     where
  19.     (==) ::!(a,b,c) !(a,b,c) -> Bool    |    Eq a & Eq b & Eq c
  20.     (==) (x1,y1,z1) (x2,y2,z2) = x1==x2 && y1==y2 && z1==z2
  21.     
  22. instance <    (a,b) |    Ord a & Ord b
  23.     where
  24.     (<) ::!(a,b) !(a,b) -> Bool    |    Ord a & Ord b
  25.     (<) (x1,y1) (x2,y2)
  26.         |    x1<x2
  27.             =    True
  28.         |    x1>x2
  29.             =    False
  30.         //    otherwise
  31.             =    y1<y2
  32.     
  33. instance <    (a,b,c) | Ord a & Ord b & Ord c
  34.     where
  35.     (<) ::!(a,b,c) !(a,b,c) -> Bool    |    Ord a & Ord b & Ord c
  36.     (<) (x1,y1,z1) (x2,y2,z2)
  37.         |    x1<x2
  38.             =    True
  39.         |    x1>x2    
  40.             =    False
  41.         //    otherwise
  42.             =    (y1,z1) < (y2,z2)
  43.     
  44. // fst        :: !(!.a,.b) -> .a                                    // t1 of (t1,t2)
  45. fst tuple :== t1 where (t1, _) = tuple
  46. // snd        :: !(.a,!.b) -> .b                                    // t2 of (t1,t2)
  47. snd tuple :== t2 where (_, t2) = tuple
  48.  
  49. // fst3    :: !(!.a,.b,.c) -> .a                                // t1 of (t1,t2,t3)
  50. fst3 tuple :== t1 where (t1, _, _) = tuple
  51. // snd3    :: !(.a,!.b,.c) -> .b                                // t2 of (t1,t2,t3)
  52. snd3 tuple :== t2 where (_, t2, _) = tuple
  53. // thd3    :: !(.a,.b,!.c) -> .c                                // t3 of (t1,t2,t3)
  54. thd3 tuple :== t3 where (_, _, t3) = tuple
  55.  
  56. curry::!.((.a,.b) -> .c) .a .b -> .c
  57. curry f x y     =  f (x,y)
  58.  
  59. uncurry :: !.(.a -> .(.b -> .c)) !(.a,.b) -> .c;
  60. uncurry f (x,y) = f x y
  61.  
  62. app2 :: !(.(.a -> .b),.(.c -> .d)) !(.a,.c) -> (.b,.d)
  63. app2 (f1, f2) (x1,x2) = (f1 x1,f2 x2)
  64.  
  65. app3 :: !(.(.a -> .b),.(.c -> .d),.(.e -> .f)) !(.a,.c,.e) -> (.b,.d,.f)
  66. app3 (f1, f2, f3) (x1,x2,x3) = (f1 x1,f2 x2,f3 x3)
  67.